<template>
  <div>
    <div class="collect-wrap">
      <span @click="shows = true">酒店收藏</span>
      <span @click="shows = false">游记收藏</span>
    </div>
    <div v-if="shows" class="hotelCollect-wrap-box">
      <div
        class="hotelCollect-wrap hotelCollectBox"
        v-for="(item, index) in hotelCollect"
        v-show="Myshow"
      >
        <img :src="item.image" alt="" @click="hotelCommDetail(item.mid)" />
        <p>{{ item.title }}</p>
        <p class="el-icon-place">： {{ item.address }}</p>
        <span
          class="el-icon-delete posticonHotel"
          @click="deleteHotil(item.mid)"
        ></span>
      </div>
      <div v-show="!Myshow" class="kong-wrap">
        <!-- 没数据的显示 -->
        <kong>
          <span>您还未收藏任何酒店喔！</span>
        </kong>
      </div>
    </div>

    <!-- 游记 -->
    <div v-if="!shows" class="hotelCollect-wrap-box destCollect-wrap-box">
      <div
        class="hotelCollect-wrap destCollect"
        v-for="(item, index) in destCollect"
        v-show="Myshowcoll"
      >
        <img :src="item.image" alt="" @click="commDetail(item.mid)" />
        <p>{{ item.title }}</p>
        <p class="el-icon-user-solid">{{ item.author }}</p>
        <span
          class="el-icon-delete posticon"
          @click="deleteDest(item.mid)"
        ></span>
      </div>

      <div v-show="!Myshowcoll" class="kong-wrap">
        <!-- 没数据的显示 -->
        <kong>
          <span>您还未收藏游记喔！！</span>
        </kong>
      </div>
    </div>
  </div>
</template>

<script>
import {mapState} from 'vuex'
import session from "../../http/session";
import kong from "../../commonality/kong.vue";
export default {
  name: "WorkspaceJsonInfo",

  data() {
    return {
      shows: true,
      Myshow: true,
      Myshowcoll: true,
      destCollect: [],
      hotelCollect: [],
    };
  },
  components: {
    kong,
  },
  mounted() {
    let that = this;
    // 游记查询
    session().then((res) => {
      this.username = res.data.data[0].uname;
      this.$http
        .get("/collectInfo", {
          params: {
            username: this.username,
          },
        })
        .then((result) => {
          // console.log(result.data.data);
          this.destCollect = result.data.data;
          if (result.data.data.length == 0) {
            that.Myshowcoll = false;
          } else {
            that.Myshowcoll = true;
          }
        });

      // 酒店查询

      this.$http
        .get("/collectInfoHotel", {
          params: {
            username: this.username,
          },
        })
        .then((results) => {
          this.hotelCollect = results.data.data;
          if (results.data.data.length == 0) {
            that.Myshow = false;
          } else {
            that.Myshow = true;
          }
        });
    });
  },

  methods: {
    // 点击进入社区详情
    commDetail(mid) {
      let urls = this.$router.resolve("/community/?mid=" + mid);
      window.open(urls.href, "_black");
    },
    // 点击进入酒店详情
    hotelCommDetail(id){
      let urls = this.$router.resolve("/detailHotel/"+id);
      window.open(urls.href, "_black");
    },

    // 点击删除当前游记收藏
    deleteDest(mid) {
      this.$confirm("此操作将永久删除该收藏, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          // 获取当前登录用户名
          this.$http
            .post("/uncollect", {
              mid: mid,
              username: this.username,
            })
            .then((results) => {
              this.$message({
                type: "success",
                message: "删除成功!",
              });
             this.$store.commit('Tickcollects', 1);
            });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },

    // 点击删除当前用户酒店收藏
    deleteHotil(mid) {
      this.$confirm("此操作将永久删除该收藏, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          // 获取当前登录用户名
          this.$http
            .post("/UnhotelCollect", {
              mid: mid,
              username: this.username,
            })
            .then((results) => {
              this.$message({
                type: "success",
                message: "删除成功!",
              });
            });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
  },
  computed:{
    ...mapState(['Tickcollects']),
			count(){
				console.log(this.Tickcollects);
			}
  }
};
</script>

<style lang="scss" scoped>
.collect-wrap {
  display: flex;
  justify-content: space-around;
  font-size: 15px;
  color: #3fa2c0;
  font-weight: bold;
  border-bottom: #d6d6d6 1px solid;
  padding: 20px 0;
  cursor: pointer;
}
/* .destCollect-wrap-box{
  height: 400px!important;
} */
.hotelCollect-wrap-box {
  width: 100%;
  max-height: 700px;
  overflow-y: scroll;
  display: flex;
  align-items: flex-start;
  flex-wrap: wrap;
  .destCollect {
    position: relative;
    height: 190px !important;
    .posticon {
      color: #ec4141;
      position: absolute;
      right: 0;
      bottom: 0;
    }
  }

  .hotelCollectBox {
    position: relative;
  }
  .posticonHotel {
    position: absolute;
    bottom: 0;
    right: 0;
    color: red;
  }
  .hotelCollect-wrap {
    padding-bottom: 5px;
    margin: 10px 15px;
    width: 310px;
    height: 270px;
    border: 1px solid rgb(233, 231, 231);
    box-sizing: border-box;
    border-radius: 3px;
    color: #494848;
    cursor: pointer;
    > img {
      width: 308px;
      height: auto;
    }
    > p:nth-child(2) {
      font-size: 15px;
      font-weight: bold;
    }
    > p:nth-child(3) {
      font-size: 12px;
      color: #4b4b4b;
    }
  }
}
.kong-wrap {
  margin-top: 50px;
  width: 100%;
  display: flex;
  flex-direction: column;
  text-align: center;
  > div {
    text-align: center;
    color: #3fa2c0;
  }
}

.card:hover {
  box-shadow: 0 0 5px rgb(194, 193, 193);
}
.card:hover .title {
  color: #41c1ec;
}
.mainRight a {
  text-decoration: none;
}
.card {
  margin-top: 10px;
  margin-bottom: 10px;
  width: 100%;
  height: 200px;
  border: 1px solid #ddd;
  background-color: white;
  box-sizing: border-box;
  padding-top: 15px;
  padding-left: 15px;
  border-radius: 5px;
  display: flex;
  box-sizing: border-box;
}
.img {
  width: 250px;
  overflow: hidden;
  height: 170px;
  overflow: hidden;
}
.img img {
  width: 300px;
}
.text {
  width: 420px;
  margin-left: 20px;
}
.title {
  white-space: nowrap;
  text-overflow: ellipsis;
  width: 90%;
  font-size: 23px;
  line-height: 23px;
  color: black;
  height: 23px;
  overflow: hidden;
}
.detail {
  margin-top: 13px;
  font-size: 17px;
  width: 90%;
  height: 87px;
  overflow: hidden;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 4;
  text-overflow: ellipsis;
  color: #808080;
  padding-right: 5px;
}
.zuozhe {
  margin-top: 15px;
  font-size: 15px;
}
.zuozhe span:nth-child(1) {
  margin-left: 5px;
  color: #808080;
}
.zuoz {
  margin-left: 15px;
}
.zztx {
  width: 23px;
  border-radius: 20px;
  vertical-align: middle;
  margin-left: 5px;
}
.zzname {
  margin-left: 3px;
  color: #41c1ec;
}
.read {
  margin-left: 20px;
  font-weight: 550;
  color: rgb(161, 161, 161);
}
.end {
  float: right;
  margin-right: 15px;
  margin-top: -5px;
}
.zan {
  color: #41c1ec !important;
}
.btn {
  height: 30px;
  line-height: 5px;
  background-color: #41c1ec !important;
  color: white;
  text-align: center;
}
.mainRightPage {
  width: 60%;
  height: 40px;
  margin-left: 420px;
  margin-bottom: 15px;
}
.mainRightPage span {
  font-size: 15px;
  color: #808080;
  line-height: 30px;
  margin-left: 15px;
  margin-right: 10px;
}
.spanpage {
  font-size: 12px;
  color: #808080;
  line-height: 40px;
}
.btnp {
  margin-left: 10px;
}
.scroolAuto {
  overflow-y: scroll;
  height: 700px;
}
</style>